text handle: Stop using ::hierarchy-changed
authorMatthias Clasen <mclasen@redhat.com>
Sat, 23 Feb 2019 05:46:44 +0000 (00:46 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 23 Feb 2019 14:43:57 +0000 (09:43 -0500)
Use notify::root instead.

gtk/gtktexthandle.c

index 84405d297e7c1c0e1b8e434dda018683a821b045..eebfcbd1291505432493ec4803e0ae19471219d8 100644 (file)
@@ -61,6 +61,7 @@ struct _HandleWindow
 struct _GtkTextHandlePrivate
 {
   HandleWindow windows[2];
+  GtkWidget *toplevel;
   GtkWidget *parent;
   GtkScrollable *parent_scrollable;
   GtkAdjustment *vadj;
@@ -217,7 +218,7 @@ _gtk_text_handle_ensure_widget (GtkTextHandle         *handle,
       gtk_widget_add_controller (widget, controller);
 
       priv->windows[pos].widget = g_object_ref_sink (widget);
-      window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW);
+      priv->toplevel = window = gtk_widget_get_ancestor (priv->parent, GTK_TYPE_WINDOW);
       _gtk_window_add_popover (GTK_WINDOW (window), widget, priv->parent, FALSE);
 
       context = gtk_widget_get_style_context (widget);
@@ -468,7 +469,7 @@ gtk_text_handle_lookup_scrollable (GtkTextHandle *handle)
 
 static void
 _gtk_text_handle_parent_hierarchy_changed (GtkWidget     *widget,
-                                           GtkWindow     *previous_toplevel,
+                                           GParamSpec    *pspec,
                                            GtkTextHandle *handle)
 {
   GtkWidget *toplevel, *scrollable;
@@ -477,11 +478,11 @@ _gtk_text_handle_parent_hierarchy_changed (GtkWidget     *widget,
   priv = handle->priv;
   toplevel = gtk_widget_get_ancestor (widget, GTK_TYPE_WINDOW);
 
-  if (previous_toplevel && !toplevel)
+  if (priv->toplevel && !toplevel)
     {
       if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget)
         {
-          _gtk_window_remove_popover (GTK_WINDOW (previous_toplevel),
+          _gtk_window_remove_popover (GTK_WINDOW (priv->toplevel),
                                       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget);
           g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget);
           priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_START].widget = NULL;
@@ -489,11 +490,13 @@ _gtk_text_handle_parent_hierarchy_changed (GtkWidget     *widget,
 
       if (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget)
         {
-          _gtk_window_remove_popover (GTK_WINDOW (previous_toplevel),
+          _gtk_window_remove_popover (GTK_WINDOW (priv->toplevel),
                                       priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget);
           g_object_unref (priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget);
           priv->windows[GTK_TEXT_HANDLE_POSITION_SELECTION_END].widget = NULL;
         }
+
+      priv->toplevel = NULL;
     }
 
   scrollable = gtk_text_handle_lookup_scrollable (handle);
@@ -521,7 +524,7 @@ _gtk_text_handle_set_parent (GtkTextHandle *handle,
   if (parent)
     {
       priv->hierarchy_changed_id =
-        g_signal_connect (parent, "hierarchy-changed",
+        g_signal_connect (parent, "notify::root",
                           G_CALLBACK (_gtk_text_handle_parent_hierarchy_changed),
                           handle);